package jdk6.httpserver.httphandler;

import java.io.IOException;
import java.io.OutputStream;

import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;

/**
 * Description: jdk1.6新特性：轻量级HttpServer（HttpServer）
 * 例子，用于处理收到的服务器请求
 * @author Kwum
 * @date 2017年6月17日 下午3:19:33
 * @version 1.0
 */

public class MyHandler implements HttpHandler{

    @Override
    public void handle(HttpExchange he) throws IOException {
//        InputStream is = he.getRequestBody();
        String response = "Hello, I'm from JDK6 HttpServer!";  
        he.sendResponseHeaders(200, response.length());  
        OutputStream os = he.getResponseBody();  
        os.write(response.getBytes());  
        os.close(); 
    }

}
